package eu.telecom_bretagne.RECRUT.servlet;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import eu.telecom_bretagne.RECRUT.service.IServiceArchive;

/**
 * Servlet implementation class CreationArchive
 */
@WebServlet("/creer_archive")
public class CreationArchive extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CreationArchive() {
		super();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String nouveauTitre = request.getParameter("titre");
		String idE = request.getParameter("employe");
		String idD = request.getParameter("dossier");

		try {
			int idEmploye = Integer.parseInt(idE);
			int idDossier = Integer.parseInt(idD);
			InitialContext ctx = new InitialContext();
			IServiceArchive serviceArchive = (IServiceArchive) ctx
					.lookup(IServiceArchive.JNDI_NAME);
			serviceArchive.creerArchive(nouveauTitre, idEmploye, idDossier);
		} catch (NamingException e) {
			throw new ServletException(e);
		}
		response.sendRedirect("index.jsp");
	}

}
